package com.example.combie;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Combie extends AppCompatActivity {

    private EditText num;
    private EditText psd;
    private Button btn;

    private class Data {
        private String id, password;
        public Data(){

        }
        public Data(String id, String password){
            this.setId(id);
            this.setPassword(password);
        }
        public String getId(){
            return this.id;
        }
        public void setId(String id){
            this.id = id;
        }
        public String getPassword(){
            return this.password;
        }
        public void setPassword(String password){
            this.password = password;
        }

    }

    private Data[] datas = {
        new Data("201958501377", "ok077"),
        new Data("201958501388", "ok088"),
        new Data("201958501399", "ok099")
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_combie);

        num = (EditText) findViewById(R.id.number);
        psd = (EditText) findViewById(R.id.password);
        btn = (Button) findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                String input_id = num.getText().toString();
                String input_psd = psd.getText().toString();
                boolean judge = false;
                for(Data each : datas){
                    if(each.getId().equals(input_id)  && each.getPassword().equals(input_psd)){
                        judge = true;
                        break;
                    }
                }
                if(judge == true) {
                    Bundle bundle = new Bundle();
                    bundle.putString("name", input_id);
                    Intent intent = new Intent(Combie.this, Hello.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }else{
                    Toast.makeText(Combie.this, "输入的学号或密码有误", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
